<?php 
class CategoryController extends AuthController{
	private $db;
	public function __init(){
		$this->db=new CategoryModel;
	}
	// 显示栏目列表
	public function index(){
		// p($_FILES);exit;
		$data=$this->db->getall();
		$this->assign("data",$data);
		$this->display('index.html');
	}
	// 添加栏目
	public function add(){	
	if(IS_POST){
			if($this->db->addCategory($_POST)){
				$this->success('添加成功',__CONTROLLER__);
			}else{
				$this->error($this->db->error);}
			}else{
			$this->display('add.html');
		}
	}
	public function update(){
		if(IS_POST){
			if($this->db->editCategory($_POST)){
				$this->success('修改成功',__CONTROLLER__);
			}else{
				$this->error($this->db->error);
			}
		}else{
			$data = $this->db->where("cid={$_GET['cid']}")->find();
			$this->assign('field',$data);
			$this->display('update.html');
		}
	}
	public function delete(){
		if ($this->db->where("cid={$_GET['cid']}")->deleteCategory($_POST)) {
			$this->success('删除成功');
		}else{
			$this->error('不能删除');
		}
	}
	
}


 ?>